package com.itheima.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.bean.Employee;
import com.itheima.common.R;
import com.itheima.service.EmployeeService;
import com.itheima.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 海关监管和对方
* @description 针对表【employee(鍛樺伐淇℃伅)】的数据库操作Service实现
* @createDate 2024-05-06 10:13:06
*/
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee>
    implements EmployeeService{

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Employee login(Employee em) {
        LambdaQueryWrapper<Employee> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Employee::getPassword,em.getPassword()).eq(Employee::getUsername,em.getUsername());
        return employeeMapper.selectOne(wrapper);
    }

    @Override
    public R<Page> pageR(Page<Employee> employeePage, String name) {
        LambdaQueryWrapper<Employee> wrapper = new LambdaQueryWrapper<>();
        //判断name是不是为空，是的话就不构造，不是就构造
        wrapper.like(StringUtils.isEmpty(name),Employee::getName,name);
        employeeMapper.selectPage(employeePage,wrapper);
        return R.success(employeePage);
    }
}




